<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>权限分配</title>
    <link rel="stylesheet" href="../../component/layui/css/layui.css"/>
    <link href="../../admin/css/font/dtreefont.css" rel="stylesheet"/>
    <link href="../../admin/css/dtree.css" rel="stylesheet"/>
    <link href="../../admin/css/pearCommon.css" rel="stylesheet"/>
</head>
<body>
<form style="margin-top: 10px;" action="javascript:void(0);" class="layui-form">
    <div  class="mainBox">
        <div class="layui-form-item">
            <ul id="dataTree3" class="dtree" data-id="0"></ul>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button class="layui-btn layui-btn-sm" lay-submit lay-filter="formDemo">保存</button>
            <button type="reset" class="layui-btn layui-btn-sm layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script src="../../component/layui/layui.js"></script>
<script type="text/javascript" th:inline="javascript">
     layui.use(['dtree','form','operate'],function(){
         var dtree = layui.dtree;
         var form = layui.form;
         var operate = layui.operate;

         //监听提交
         form.on('submit(formDemo)', function(data){

             var param = dtree.getCheckbarNodesParam("dataTree3");

             var ids ='';

             for(var i=0;i<param.length;i++){
                 var id = param[i].nodeId;
                 ids+=id+',';
             }

             //截取
             ids = ids.substr(0,ids.length-1);

             data.field.roleId = [[${roleId}]];
             data.field.powerIds = ids;

             var loading = layer.load();

             operate.get('/system/power/savePowerByRoleId',data.field,function(result){

                 layer.close(loading);

                 if(result.code==200){

                     operate.success(result.msg,function(){

                         //关闭当前窗体
                         var index = parent.layer.getFrameIndex(window.name);
                         parent.layer.close(index);

                     });

                 }else{
                     operate.failure(result.msg);
                 }
             })



         });

         dtree.render({
             elem: "#dataTree3",
             url: "/system/power/getPowerByRoleId/"+[[${roleId}]],
             method:'get',
             skin: "layui",
             dataStyle: "layuiStyle",
             dataFormat: "list",
             checkbar: true,
             checkbarType:"no-all",
             response:{message:"msg",statusCode:0, treeId: "id", parentId: "parentId", title: "name"}
         });

     })
</script>
</body>
</html>